//
//  httpTool.swift
//  AFNTest
//
//  Created by Admin on 2016/11/1.
//  Copyright © 2016年 Admin. All rights reserved.
//

import UIKit

class httpTool: AFHTTPSessionManager {
    
    func creatUser(person:person,sucess:@escaping (_ responseObject:AnyObject?)->(),failure:@escaping (_ Error:NSError?)->()) {
        let url = "http://device.camry.cn/feiheinternational/v1/user/register"
        let parameters = ["name":person.name,"password":person.password,"account":person.account,"birthday":person.birthday,"sex":String(person.sex),"height":String(person.height),"activity":String(person.activity),"userKind":String(person.userKind)]
        let httpManager = AFHTTPSessionManager()
        httpManager.responseSerializer.acceptableContentTypes = NSSet(objects:"application/json","text/json","text/javascript","text/html","text/plain")as? Set<String>
        httpManager.post(url, parameters: parameters, progress:nil, success: { (NSURLSessionDataTask, responseObject) in
            //如果responseObject不为空时
            if responseObject != nil {
                sucess(responseObject! as AnyObject?)
//                print(responseObject!)
            }
            
        }, failure:{ (NSURLSessionDataTask, error) in
            failure(error as NSError?)
//            print(error)
        })
    }
    func Login(person:person,sucess:@escaping (_ reponseObject:AnyObject?)->(),failure:@escaping (_ Error:NSError?)->()) {
        let url = "http://device.camry.cn/feiheinternational/v1/user/login"
        let parameters = ["password":person.password,"account":person.account]
        let httpManager = AFHTTPSessionManager()
        httpManager.responseSerializer.acceptableContentTypes = NSSet(objects:"application/json","text/json","text/javascript","text/html","text/plain")as? Set<String>
        httpManager.post(url, parameters: parameters, progress: {(Progress) in}, success: {(URLSessionDataTask, responseObject)in
            sucess(responseObject! as AnyObject?)
//            print(responseObject!)
        }, failure: {(URLSessionDataTask, error) in
            failure(error as NSError?)
//            print(error)
        })
    }
    
}
